/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package abricots.net.common;

import abricots.command.Command;
import abricots.entity.state.EntityState;
import java.util.List;

/**
 *
 * @author charly
 */
public class GameMessage {

    public int id;
    public int ackId;
    public boolean reliable;
    public int relAckId;

    public GameMessage() {
        id = -1;
        ackId = -1;
        reliable = false;
        relAckId = -1;
    }

    public static class GameTimeSyncMessage extends GameMessage {

        public long gameTime;
        public long newGameTime;

        public GameTimeSyncMessage() {
        }

        public GameTimeSyncMessage(long gameTime, long newGameTime) {
            this.gameTime = gameTime;
            this.newGameTime = newGameTime;
        }

        @Override
        public String toString() {
            return "GameTimeSyncMessage{" + "gameTime=" + gameTime + ", newGameTime=" + newGameTime + '}' + super.toString();
        }
    }

    /**
     * entityId=-1 => client asking to validate a new entity
     */
    public static class EntityMessage extends GameMessage {

        public int localEntityId;
        public int entityId;
        public int entityTypeId;

        public EntityMessage() {
        }

        public EntityMessage(int localEntityId, int entityId, int entityTypeId) {
            this.localEntityId = localEntityId;
            this.entityId = entityId;
            this.entityTypeId = entityTypeId;
        }

        @Override
        public String toString() {
            return "  NewEntityMessage{" + "localEntityId=" + localEntityId + ", entityId=" + entityId + ", entityTypeId=" + entityTypeId + '}' + super.toString();
        }
    }

    public static class WorldDiffMessage extends GameMessage {

        public long fromTime;
        public long toTime;
        public List<EntityMessage> newEntities;
        public List<EntityMessage> removedEntities;
        public List<EntityState> modifiedStates;

        public WorldDiffMessage() {
        }

        public WorldDiffMessage(long fromTime, long toTime, List<EntityMessage> newEntities, List<EntityMessage> removedEntities, List<EntityState> modifiedStates) {
            this.fromTime = fromTime;
            this.toTime = toTime;
            this.newEntities = newEntities;
            this.removedEntities = removedEntities;
            this.modifiedStates = modifiedStates;
        }

        @Override
        public String toString() {
            return "WorldDiff:: " + "from:" + fromTime + " to:" + toTime + " " + newEntities.size() + " new, " + removedEntities.size() + " removed, " + modifiedStates.size() + " modified ::WorldDiff " + super.toString();
        }
    }

    public static class CommandsMessage extends GameMessage {

        public long fromTime;
        public long toTime;
        public int entityId;
        public List<Command> commands;

        @Override
        public String toString() {
            return "Commands:: " + "from:" + fromTime + " to:" + toTime + " entity:" + entityId + " " + (commands != null ? commands.size() + " commands" : "EMPTY") + " ::Commands " + super.toString();
        }
    }

    @Override
    public String toString() {
        return "[id:" + id + " ack:" + ackId + " relAck:" + relAckId + (reliable ? " reliable]" : "]");
    }
}
